package thread.executor.demo1;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;

public class ThreadPoolUtil {

//    private static ScheduledExecutorService executorService;
//
//    public ThreadPoolUtil() {
//        executorService = new ScheduledThreadPoolExecutor(3 ,
//                new BasicThreadFactory.Builder().namingPattern("syncdate-schedule-pool-%d").build());
//    }
//
//    private static class PluginConfigHolder {
//        private final static ThreadPoolUtil Instance = new ThreadPoolUtil();
//    }
//
//    public static ThreadPoolUtil getInstance() {
//        return PluginConfigHolder.Instance;
//    }
//
//    public ScheduledExecutorService getThreadPool() {
//        return executorService;
//    }
//
//
//    public static void main(String[] args) {
//        new ThreadPoolUtil();
//        executorService.scheduleAtFixedRate(new MyRunnable(),10,1,TimeUnit.SECONDS);
//    }


//    private final ScheduledExecutorService scheduler =
//            Executors.newScheduledThreadPool(3);
//
//    public void beepForAnHour() {
//        final Runnable beeper = new Runnable() {
//            public void run() {
//                System.out.println("beepForAnHour:" + Thread.currentThread().getName());
//                System.out.println("beep");
//                try {
//                    Thread.sleep(3000L);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            }
//        };
//
//        final ScheduledFuture<?> beeperHandle =
//                scheduler.scheduleAtFixedRate(beeper, 0, 1, TimeUnit.SECONDS);
//        scheduler.schedule(new Runnable() {
//            public void run() {
//                System.out.println("123456");
//                System.out.println(Thread.currentThread().getName());
//                beeperHandle.cancel(true);
//            }
//        }, 5 , TimeUnit.SECONDS);
//    }
//
//    public static void main(String[] args) {
//        ThreadPoolUtil threadPoolUtil = new ThreadPoolUtil();
//        threadPoolUtil.beepForAnHour();
//    }


    private final static ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    static  int i = 0;
    public static void main(String[] args) throws ExecutionException, InterruptedException {

   /*     Map<Integer, Object> map = new HashMap<>();

        ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                int[] s = new int[1];
                System.out.println(i++ + "OK" + Thread.currentThread().getName());
                i++;

            }
        }, 0, 1, TimeUnit.SECONDS);
        map.put(10,future);

        while (true) {
            System.out.println(i);
            Object o = (ScheduledFuture)map.get(i);
            if (o != null) {
                ((ScheduledFuture) o).cancel(true);
            }
            Thread.sleep(1000L);
        }*/
        int sunSum = 2*Runtime.getRuntime().availableProcessors();
        System.out.println(sunSum);
    }


}
//
//class MyRunnable implements Runnable {
//    @Override
//    public void run() {
//        System.out.println(1);
//        System.out.println(Thread.currentThread().getName());
//    }
//}